$(document).ready(function(){
	
	  
 	 $("#temp").hide();
 	
 		$("#cancel").click(function (event) {
			
			
			
			 $("#temp").hide();
			 $(".error").hide();
		});
		

	 
	$("#save").click(function () {
		
		 $("#temp").hide();
		 
		$(".error").remove();
      var hasError = false;
      var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
      var phoneReg = /^(\+33\.|0)[0-9]{9}$/;
      var numbeReg = /^[0-9]{5}$/;
      var emailaddressVal = $("#u_email").val();
      var phoneVal = $("#u_phonenumber").val();
      var codepVal = $("#u_codep").val();
   
      if(phoneVal == '') {
          $("#u_phonenumber").after('<br class="error"><span class="error" style ="color: red;">Veuillez saisir un numero de t\351l\351phone.</span>');
          hasError = true;
      }
      
      if(!phoneReg.test(phoneVal)) {
          $("#u_phonenumber").after('<br class="error"><span class="error" style ="color: red;">Veuillez saisir un numero de t\351l\351phone valide.</span><br>');
          hasError = true;
      }
      if(emailaddressVal == '') {
          $("#u_email").after('<br class="error"><span class="error" style ="color: red;">Veuillez saisir votre adresse e-mail.</span>');
          hasError = true;
      }
      if($("#u_city").val() == '') {
    	  console.log("ddddddd");
          $("table").after('<br class="error"><span class="error" style ="color: red;">Veuillez saisir la ville.</span>');
          hasError = true;
      }
    
      if(!numbeReg.test(codepVal)) {
          $("table").after('<br class="error"><span class="error" style ="color: red;">Veuillez saisir un code postal valide.</span><br>');
          hasError = true;
      }
      else if(!emailReg.test(emailaddressVal)) {
          $("#u_email").after('<br class="error"><span class="error" style ="color: red;">Veuillez saisir votre adresse e-mail valide.</span><br>');
          hasError = true;
      }
      if(hasError == false){
      	$("#temp").show();
      	$("#temp2").show();
      	$('html,body').animate({scrollTop: 0});
      	}

      if(hasError == true) { 
      	return false; 
      	}
      
      
          return false;
      
 });
	

});